<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    function* something() {
        try {
            var nextVal = 0;
            while (true) {
                if (nextVal == undefined) {
                    nextVal = 1;
                } else {
                    nextVal = (3 * nextVal) + 6;
                }
                console.log(nextVal)
                yield nextVal;
            }

        }
        // catch(error){
        //     console.log(error);
        // }
        finally {
            console.log("cleaning up");
            yield 3;
            yield 4;        // 使用了return等的行为（包括在for of中的break等）会跳进finally中，但是还是可以继续迭代
        }
    }

    var it = something();
    it.next();
    it.next();
    it.throw("哈哈哈");         // 会直接跳转到内部
    // it.throw(new Error("hahaha"));      //  若是生成器内部的catch没有的话，就会重新回到外面
</script>

</html>